package day05;


import java.util.Arrays;

public class MaxOfArray {
    public static void main(String[] args) {
        //找最大值
        int[] arr = new int[10];
        for (int i = 0; i < arr.length; i++) {
            arr[i] = (int) (Math.random() * 100);
            System.out.print(arr[i] + " ");
        }
        int max = arr[0];
        for (int i = 0; i < arr.length; i++) {
            if (max < arr[i]) {
                max = arr[i];
            }
        }
        System.out.println("max=" + max);
        arr = Arrays.copyOf(arr, arr.length + 1);//扩容
        arr[arr.length - 1] = max;//将最大值max赋值到最后一个元素上
        System.out.println();
        for (int i = 0; i < arr.length; i++) {
            System.out.print(arr[i] + " ");
        }
        System.out.println("\n------------------------");


        //冒泡排序
        /*
        int[] arr1 = new int[10];
        for (int z = 0; z < arr1.length; z++) {
            arr1[z] = (int) (Math.random() * 100);
        }
        System.out.println("排序前");
        for (int i = 0; i < arr1.length; i++) {
            System.out.print(arr1[i] + " ");
        }
        System.out.println();
        //冒泡体
        for (int i = 1; i < arr1.length; i++) {
            for (int j = 0; j < arr1.length - 1; j++) {
                if (arr1[j] > arr1[j + 1]) {
                    int num = arr1[j];
                    arr1[j] = arr1[j + 1];
                    arr1[j + 1] = num;
                }
            }
        }
        System.out.println("------------------------");
        System.out.println("排序后");
        for (int i = 0; i < arr1.length; i++) {
            System.out.print(arr1[i] + " ");
        }
         */


    }
}
